#include <iostream>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

int g_val=0;


void show(const char* str)
{
	g_val++;
	std::cout<<str<<" say# "<<g_val<<std::endl;
}


void* run(void* args)
{
	while(true)
	{
		//std::cout<<"new thread " <<(char*)args <<getpid()<<std::endl;
		show("new thread");
		sleep(1);
	}
	return nullptr;

}


int main()
{
	pthread_t tid;
	int ret;
	if(ret=pthread_create(&tid,nullptr,run,(void*)"thread-1 "))
	{
		fprintf(stderr,"pthread_create error:%s",strerror(ret));
		exit(EXIT_FAILURE);
	}
	// 主线程
	while(true)
	{
		//std::cout<<"main thread: " <<getpid()<<std::endl;
		show("main thread");
		sleep(1);
	}
	return 0;
}

